﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Web;

using Obsidian.Config;
using Obsidian.Utils;

namespace Obsidian.Web
{

    public class ErrorPage
    {

        public static void Redirect(StatusCode statusCode)
        {
            Redirect(statusCode, null);
        }

        public static void Redirect(StatusCode statusCode, Dictionary<string, object> urlParams)
        {
            string status = Enum.GetName(typeof(StatusCode), statusCode).Replace("Status", "");
            ErrorPageConifg.ErrorPageInfo info = ErrorPageConifg.GetErrorPage(status);

            string url = info.Url;

            if (String.IsNullOrEmpty(url))
                throw new Exception("Url属性不能为空");

            if (urlParams != null)
                url = WebUtil.CreateUrl(url, urlParams);

            HttpContext.Current.Response.Redirect(url);
        }

        public static bool Has(StatusCode statusCode)
        {
            string status = Enum.GetName(typeof(StatusCode), statusCode).Replace("Status", "");
            return ErrorPageConifg.HasStatus(status);
        }
        
        public enum StatusCode
        {
            Status404,
            Status500
        }

    }


}
